package com.hyl.controller;

import com.alibaba.fastjson.JSON;
import com.hyl.entity.SysRole;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

/**
 * @Description TODO
 * @Author com.hyl
 * @Date 2022/10/15 9:32
 **/
@Controller
@RequestMapping("/role")
public class RoleController {

	Logger logger = Logger.getLogger(RoleController.class);

	@RequestMapping("/toAdd")
	public String toAdd(){
		logger.info("进入添加页面");
		return "sysRole/add";
	}

	@RequestMapping("/add")
	public String add(){
		logger.info("添加");
		return "redirect:role/list"; //重定向==》获取列表数据
	}


	@RequestMapping("/list")
	public String list(){
		logger.info("列表");
		return "sysRole/list";
	}

	@ResponseBody //处理ajax请求
	@GetMapping(value = "/simpleList"
			/*,produces = "application/json;charset=UTF-8"*/)
	public String simpleList(HttpServletResponse response){

		List<SysRole> list = new ArrayList<>();

		SysRole role = new SysRole(1, "管理员");
		list.add(role);
		 role = new SysRole(2, "供应商");
		list.add(role);
		 role = new SysRole(3, "普通用户");
		list.add(role);

		return JSON.toJSONString(list);
	}


	@RequestMapping("/toUpdate")
	public String toUpdate(){
		logger.info("进入修改页面");
		return "sysRole/update";
	}

	@RequestMapping("/update")
	public String update(){
		logger.info("修改");
		return "redirect:role/list"; //重定向==》获取列表数据
	}

	@RequestMapping("/del")
	public String del(){
		logger.info("删除");
		return "sysRole/update";
	}
}
